#include <QDebug>

#include "Server.h"
#include "XmlStatsHandler.h"

XmlStatsHandler::XmlStatsHandler( Server *server )
    : mServer( server )
{
}

bool XmlStatsHandler::fatalError( const QXmlParseException &exception )
{
    qWarning() << "Fatal error on line" << exception.lineNumber()
               << ", column" << exception.columnNumber() << ":"
               << exception.message();

    return false;
}

bool XmlStatsHandler::startElement( const QString &namespaceURI, const QString &localName,
                   const QString &qName, const QXmlAttributes &atts )
{
    if ( qName == "load_1" )
    {
        float value = atts.value( "value" ).toFloat();
        mServer->setLoadOne( value );
    }
    else if ( qName == "load_5" )
    {
        float value = atts.value( "value" ).toFloat();
        mServer->setLoadFive( value );
    }
    else if ( qName == "load_15" )
    {
        float value = atts.value( "value" ).toFloat();
        mServer->setLoadFifteen( value );
    }

    return true;
}
